from uniswap import Uniswap

address = "0xFBef33e09081236cC4A1f8D2C175E9fEf6Aa2DFa"  # or "0x0000000000000000000000000000000000000000", if you're not making transactions
private_key = "0x700c472fef576757270df5068e0ec7152e7307000cfe3fbf5d15be43bde55230"  # or None, if you're not going to make transactions

uniswap_wrapper = Uniswap(
    address, private_key, version=2, provider="http://localhost:8545"
)

eth = "0x0000000000000000000000000000000000000000"
bat = "0x0D8775F648430679A709E98d2b0Cb6250d2887EF"
dai = "0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359"


# 查询代币余额
balance = uniswap_wrapper.get_token_balance(dai)
print("dai balance before trading:", balance / 10 ** 18)

# 查询eth余额
b2 = uniswap_wrapper.get_eth_balance()
print("eth balance before trading:", b2 / 10 ** 18, "\n")

# 查询代币价格
price = uniswap_wrapper.get_price_input(eth, dai, 1 * 10 ** 18)
print(" eth/dai price:", price / 10 ** 18, "\n")

# 交易: 用1个eth换dai，即swap
t = uniswap_wrapper.make_trade(eth, dai, 1 * 10 ** 18)

# 查询代币余额
balance = uniswap_wrapper.get_token_balance(dai)
print("dai balance after trading:", balance / 10 ** 18)

# 查询eth余额
b2 = uniswap_wrapper.get_eth_balance()
print("eth balance after trading:", b2 / 10 ** 18)
